<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('修改素材分组')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-group-edit" th:object="${group}">
			<input name="groupId" type="hidden" th:field="*{groupId}" />
			<input id="treeId" name="parentId" type="hidden" th:field="*{parentId}" />
			<div class="form-group">
				<label class="col-sm-3 control-label">上级分组：</label>
				<div class="col-sm-8">
				    <div class="input-group">
						<input class="form-control" type="text" id="treeName" onclick="selectGroupTree()" readonly="true" th:value="${group.parentName == null ? '无' : group.parentName}">
					    <span class="input-group-addon"><i class="fa fa-search"></i></span>
				    </div>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">分组名称：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="groupName" th:field="*{groupName}" id="groupName" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label is-required">显示排序：</label>
				<div class="col-sm-8">
					<input class="form-control" type="text" name="sort" th:field="*{sort}" required>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix =  ctx + "shop/material/group"
		
		$("#form-group-edit").validate({
			onkeyup: false,
			rules:{
				sort:{
					digits:true
				},
			},
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/edit", $('#form-group-edit').serialize());
	        }
	    }
	
		/*部门管理-修改-选择分组树*/
		function selectGroupTree() {
			var deptId = $("#treeId").val();
			var excludeId = $("input[name='groupId']").val();
			if(deptId > 0) {
			    var options = {
					title: '分组选择',
					width: "380",
					url: prefix + "/selectGroupTree/" + $("#treeId").val() + "/" + excludeId,
					callBack: doSubmit
				};
				$.modal.openOptions(options);
			} else {
        		$.modal.alertError("父分组不能选择");
        	}
		}
		
		function doSubmit(index, layero){
	   			var body = $.modal.getChildFrame(index);
	   			$("#treeId").val(body.find('#treeId').val());
	   			$("#treeName").val(body.find('#treeName').val());
	   			$.modal.close(index);
		}
	</script>
</body>
</html>
